package com.example.demo6.ui.pickup;

import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;

import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.navigation.NavController;
import androidx.navigation.Navigation;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.os.RecoverySystem;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;

import com.example.demo6.R;
import com.example.demo6.SQLite.LostGoods;
import com.example.demo6.SQLite.PickupGoods;
import com.example.demo6.databinding.FragmentLoseBinding;
import com.example.demo6.databinding.FragmentPickupBinding;
import com.example.demo6.ui.lose.LoseViewModel;
import com.example.demo6.ui.lose.LostAdapter;

import java.util.ArrayList;
import java.util.List;

public class pickupFragment extends Fragment {

    RecyclerView recyclerView;

    PickupViewModel pickupViewModel;

    private List<PickupGoods> pickupGoodsList;

    PickupAdapter pickupAdapter;

    private FragmentPickupBinding binding;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        binding=FragmentPickupBinding.inflate(inflater, container, false);
        View root=binding.getRoot();
        recyclerView=root.findViewById(R.id.pickuprecyclerView);
        recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
        pickupGoodsList=new ArrayList<>();
        pickupAdapter=new PickupAdapter(getContext(),pickupGoodsList);
        recyclerView.setAdapter(pickupAdapter);
        PickupViewModel recyclerViewViewModel = new ViewModelProvider(this).get(PickupViewModel.class);
        recyclerViewViewModel.getlistLiveData().observe(getViewLifecycleOwner(), new Observer<List<PickupGoods>>() {
            @Override
            public void onChanged(List<PickupGoods> pickupGoods) {
                pickupGoodsList.clear();
                pickupGoodsList.addAll(pickupGoods);
                pickupAdapter.notifyDataSetChanged();
            }
        });
//        return inflater.inflate(R.layout.fragment_pickup, container, false);
        return root;
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
//        super.onViewCreated(view, savedInstanceState);

//        Button buttonGoToLogin = view.findViewById(R.id.pickupbtn);
//        buttonGoToLogin.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                NavController navController = Navigation.findNavController(v); // 使用按钮视图找到NavController
//                navController.navigate(R.id.edit_pickup_informationFragment); // 根据action_id导航
//            }
//        });
    }
}